import React, { Component } from 'react';
import {
  View,Text,StyleSheet,ScrollView,TouchableOpacity,Image
} from 'react-native';
import pxToDp from '../common/comm';
import { StackNavigator } from 'react-navigation';
import PersonalCenter from './PersonalCenter';
import AccountAli from './AccountAli';
import AccountBank from './AccountBank';
import * as DATA from '../data/data';

export default class Info extends Component {
  constructor(props){
    super(props);
    this.state = {
      userInfo:this.props.navigation.state.params.userInfo,
        isHasAccount:false
    }
  }

    //判断渠道是否完善
    isHasAccount(){
        let _that = this;
        let data2 = 'loginkey='+this.state.userInfo.loginkey;
        fetch(DATA.ACCOUNT_URL,{
            method: "POST",
            headers:{'Content-Type': 'application/x-www-form-urlencoded' },
            body: data2
        })
            .then((response) => {       // 数据解析方式
                if (response.ok) {
                    return response.json();
                }
            })
            .then((responseData) => {       // 获取到的数据处理
                if(responseData.status == 1){
                    if(responseData.zfb !== null || responseData.yhk !== null){
                        _that.setState({
                            isHasAccount:true
                        })
                    }
                }
            })
            .catch((error) => { // 错误处理
                alert('Mypage获取数据失败，请重试！');
            })
            .done();
    }

  render() {
    return (
      <ScrollView
        contentContainerStyle={styles.contentContainer}
        >
        {/*个人信息*/}
      <TouchableOpacity
        onPress={() => {
            this.props.navigation.navigate('PersonalCenter',{userInfo:this.state.userInfo});
          }}  
            >
          <View style={styles.row}>
            <Image style={styles.itemIcon} source={{uri:DATA.PERSONAL_IMG}}/>
            <Text style={[styles.title,{fontSize:pxToDp(36)}]}>个人信息</Text>
            <Image style={[styles.next,{marginLeft:pxToDp(230)}]} source={{uri:DATA.ENTER_IMG}}/>
          </View>
        </TouchableOpacity>
        {/*渠道信息完善*/}
        <TouchableOpacity
          onPress={() => {

            this.props.navigation.navigate('Account',{userInfo:this.state.userInfo,isHasAccount:this.state.isHasAccount});
          }}
            >
          <View style={styles.row}>
            <Image style={styles.itemIcon} source={{uri:DATA.ALIPAY_IMG}}/>
            <Text style={[styles.title,{fontSize:pxToDp(36)}]}>渠道信息完善</Text>
            <Image style={[styles.next,{marginLeft:pxToDp(230)}]} source={{uri:DATA.ENTER_IMG}}/>
          </View>
        </TouchableOpacity>
      </ScrollView>
    );
  }
}

var styles = StyleSheet.create({
    contentContainer: {
      paddingVertical: 20
  },
  bg: {
    backgroundColor: '#fff',
  },
  item: {
    flexDirection: 'row',
    paddingTop: pxToDp(15),
    paddingLeft:pxToDp(30),
    alignItems:'center'
  },
  userIcon: {
    width: pxToDp(120),
    height:pxToDp(120)
  },
  next: {
    width: pxToDp(40),
    height: pxToDp(40),
    position:'absolute',
    right:pxToDp(30)
  },
  title: {
    marginLeft:pxToDp(30)
  },
  itemIcon:{
    width:pxToDp(50),
    height:pxToDp(50)
  },
  row:{
    flexDirection:'row',
    alignItems:'center',
    backgroundColor:'#fff',
    height:pxToDp(80),
    marginTop:pxToDp(40),
    paddingLeft:pxToDp(50)
  }
});

  